/* =============================================================================
#     FileName: wl_queue.h
#     Desc:
#     LastChange:
#     History:
============================================================================= */
#ifndef __WL_QUEUE_H
#define __WL_QUEUE_H

#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>

enum {
	WL_QUEUE_ERROR_NULL = 0,
    WL_QUEUE_ERROR_PARAM,
    WL_QUEUE_ERROR_SEND_FAILED,
    WL_QUEUE_ERROR_RCV_FAILED,
};

#define QUEUE_USAGE_ENABLE  

/* ------------------------------------------------Exported enmu   -----------------------------------------------*/
/* Queue ID list */
typedef enum
{
    WL_QUEUE_COMM_ID = 0,   //  for communication task
    WL_QUEUE_CONTROL_ID,
    WL_QUEUE_SUBG_ID,
    WL_QUEUE_BMS_ID,
    WL_QUEUE_FAC_ID,
    WL_QUEUE_TCU_ID,

    WL_QUEUE_MAX_ID
}QueueID_e;


enum __MSG_ID_
{
    WL_MSG_COMM_BASE_ID = (WL_QUEUE_COMM_ID<<8),
    WL_MSG_COMM_RX_UART2_DATA,
    WL_MSG_COMM_RX_UART3_DATA,
    WL_MSG_COMM_RX_UART4_DATA,
    WL_MSG_COMM_RX_UART6_DATA,
    WL_MSG_COMM_RX_UART5_DATA,
    WL_MSG_COMM_RX_SPI1_DATA,

    WL_MSG_COMM_TX_UART1_DATA,
    WL_MSG_COMM_TX_UART2_DATA,
    WL_MSG_COMM_TX_UART3_DATA,
    WL_MSG_COMM_TX_UART4_DATA,
    WL_MSG_COMM_TX_UART6_DATA,
    
    
    WL_MSG_CTRL_BASE_ID = (WL_QUEUE_CONTROL_ID<<8),
    WL_MSG_CTRL_DUMMY_ID,
    WL_MSG_CTRL_10MS_ID,
    WL_MSG_LIFTUP_BUMPER_HALL_CHANGE,


    WL_MSG_SUBG_BASE_ID = (WL_QUEUE_SUBG_ID<<8),
    WL_MSG_SUBG_DATA_INT_ID,
    WL_MSG_SUBG_FREQHOP_INT_ID,
    WL_MSG_SUBG_CYCLE_ID,


    WL_MSG_BMS_BASE_ID = (WL_QUEUE_BMS_ID<<8),
    WL_MSG_BMS_STATE_ID,
    WL_MSG_BMS_CTRL_ID,
    WL_MSG_BMS_DATA_ID,


    WL_MSG_FAC_BASE_ID = (WL_QUEUE_FAC_ID<<8),
    WL_MSG_COMM_RX_UART1_DATA,
    WL_MSG_SUBG_REINIT,
    
    WL_MSG_TCU_BASE_ID = (WL_QUEUE_TCU_ID<<8),
    WL_MSG_TCU_CYCLE_ID,
    WL_MSG_COMM_TX_UART5_DATA,

    WL_MSG_MAX
};


/* ------------------------------------------------Exported stuct  -----------------------------------------------*/
typedef struct
{
    uint16_t u16MsgId;
    uint16_t u16SubMsgId;
    uint32_t u32Param;
}Msg_st;

typedef struct
{
    char*    ps8Name;
    uint32_t u32QueueLength;
}RRQueue_t;


void wl_queue_init(void);
int32_t wl_queue_is_full(uint32_t u32Qid, uint8_t s32InIsr);
int32_t wl_queue_is_empty(uint32_t u32Qid);
int32_t wl_queue_send(uint32_t u32Qid,  uint16_t u16MsgId, uint16_t u16SubMsgId, uint32_t u32Param, uint32_t u32TicksToWait);
int32_t wl_queue_send_isr(uint32_t u32Qid,  uint16_t u16MsgId, uint16_t u16SubMsgId, uint32_t u32Param);
int32_t wl_queue_receive(uint32_t u32Qid, void* pvBuffer, uint32_t u32TicksToWait);
#ifdef QUEUE_USAGE_ENABLE
int32_t wl_queue_max_used(uint32_t u32Qid);
#endif
int32_t wl_queue_length(uint32_t u32Qid);
void wl_queue_status_display(void);

#endif /*__WL_QUEUE_H */
